var e$,ebayJSHelper;
(function(win){
var doc = win.document,
	nav = win.navigator,
	loc = win.location;
var appName={
  ie:'Microsoft Internet Explorer',
  netscape:'Netscape',
  opera:'Opera'
}
var browserName={
  ie:'MSIE',
  firefox:'Firefox',
  safari:'Safari',
  opera:'Opera',
  chrome:'Chrome'
}
ebayJSHelper = e$ = {
  JSReady:false,
  ProductId:'unknown',
  ProductType:'unknown',
  is_ie:function(){
    return nav.appName==appName.ie;
  },
  is_ready:function(){
    return this.JSReady;
  },
  getProductId:function(){
    return this.ProductId;
  },
  getProductType:function(){
	return this.ProductType;
  },
  getById:function(id){
    return doc.getElementById(id);
  },
  getByTag:function(tag,obj){
    return obj.getElementsByTagName(tag);
  },
  getFlash:function(id){
	  if(nav.userAgent.indexOf(browserName.safari)!=-1){
		  return win[id][1];
	  }else{
		  return doc[id];
	  }
  },
  getByClass:function(className,obj){
	var parent = obj?obj:doc;
    if (parent.getElementsByClassName == undefined) {
		var hasClassName = new RegExp("(?:^|\\s)" + className + "(?:$|\\s)");
		var allElements = parent.getElementsByTagName("*");
		var results = [];
		var element;
		for (var i = 0; (element = allElements[i]) != null; i++) {
			var elementClass = element.className;
			if (elementClass && elementClass.indexOf(className) != -1 && hasClassName.test(elementClass))
				results.push(element);
		}
		return results;
    }else{
	  return parent.getElementsByClassName(className);
	}
  },
  makeElem:function(tagName){
    return doc.createElement(tagName);
  },
  getOffset:function(obj){
	var offset = new Object();
	offset.left = offset.top = 0;
	
	if(obj.offsetParent){
	  do{
		  offset.left += obj.offsetLeft;
		  offset.top += obj.offsetTop;
	  }while(obj = obj.offsetParent);
	}
	return offset;
  },
  ajaxFeedFromFlash:function(obj){
    for (var name in obj){
	  e$.println(name+":"+obj[name]);
	}
    
  },
  filterElems:function(arr){
    var newArr= [];
    for(var i=0; i<arr.length; i++){
	    if(arr[i].nodeType && arr[i].nodeType=="1"){
		  newArr.push(arr[i]);
		}
	}
	return newArr;
  },
  enlargImg:function(imgs,relObj,engImg,scale){
    scale = scale||1.6;
	for(var i=0; i<imgs.length; i++){
	  var mouseover = function(e){
	    engImg.src = this.src;
		engImg.style.width = this.clientWidth*scale+'px';
	    engImg.style.height = this.clientHeight*scale+'px';
	    engImg.style.display = 'inline';
	    e?mousemove(e):mousemove();
	  };
	  var mousemove = function(e){
		var offset = e$.getOffset(relObj);
		var mouseX,mouseY,relX,relY;
        if(e$.is_ie()){
		  mouseX = event.clientX + doc.body.scrollLeft+doc.documentElement.scrollLeft;
		  mouseY = event.clientY + doc.body.scrollTop +doc.documentElement.scrollTop;
        }else{
          mouseX = e.pageX;
       	  mouseY = e.pageY;
        }
        relX = mouseX - offset.left;
        relY = mouseY - offset.top;
	    engImg.style.top = (relY+20)+'px';
	    engImg.style.left = (relX+20)+'px';
	  };
	  var mouseout = function(e){
	    engImg.style.display = 'none';
	  };
	  imgs[i].onmouseover = mouseover;
	  imgs[i].onmousemove = mousemove;
	  imgs[i].onmouseout = mouseout;
	  
	}
  },
  hasInterface:function(name){
	  if(e$[name] == undefined)return false;
	  return true;
  },
  feedJSON:function(data){
	  if(data && typeof data === 'object'){
		  if(data.pass){
			  if(data.key && data.data && e$[data.key] && typeof e$[data.key] === 'function'){
				  e$[data.key](data);
			  }
		  }
	  }
  },
  setupPage:function(){
  },
  println:function(text){
    var output=e$.getById('hyOutput');
	if(output){
	  output.innerHTML +=text+'<br />';
	}
  },
  output:function(text){
    var o = e$.getById('hyOutput');
	if(o){
	  o.innerHTML = text;
	}
  }
}
win.e$=ebayJSHelper;
})(window)
